package com.xzxy.xmlg_backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 定时任务配置类
 * @author 周毅盛
 * @since 2025-06-16
 */
@Configuration
@EnableScheduling
public class ScheduleConfig {

    /**
     * 配置任务调度器
     * @return TaskScheduler
     */
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        // 设置线程池大小
        scheduler.setPoolSize(10);
        // 设置线程名前缀
        scheduler.setThreadNamePrefix("announcement-schedule-");
        // 设置等待任务完成后再关闭线程池
        scheduler.setWaitForTasksToCompleteOnShutdown(true);
        // 设置等待时间
        scheduler.setAwaitTerminationSeconds(60);
        // 初始化
        scheduler.initialize();
        return scheduler;
    }
}